package com.lagou.mr.partition;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class PartitionDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);

        job.setJarByClass(PartitionDriver.class);
        job.setMapperClass(PartitionMapper.class);
       // job.setPartitionerClass(CustomPartitioner.class);
        job.setReducerClass(PartitionReduce.class);


        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(PartitionBean.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(PartitionBean.class);

        job.setPartitionerClass(CustomPartitioner.class);

        //5 指定reducetask的数量与分区数量保持一致,分区数量是3
        job.setNumReduceTasks(3); //reducetask不设置默认是1个
//        job.setNumReduceTasks(5);
//        job.setNumReduceTasks(2);
        // 6 指定输入和输出数据路径
        FileInputFormat.setInputPaths(job,new Path("E:\\input\\speak.data"));
        FileOutputFormat.setOutputPath(job,new Path("e:/output"));
        // 7 提交任务
        boolean flag = job.waitForCompletion(true);

        System.exit(flag? 0:1 );


    }
}
